﻿namespace Services
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using DAL;
    using Entities;
    using System.ComponentModel.Composition;

    [Export(typeof(IFilterService))]
    public class FilterService : IFilterService
    {
        #region Member Variables

        protected readonly IAuditedOperationRepository _auditedOperationRepository;
        protected readonly IUserRepository _usersRepository;

        #endregion

        #region Constructor

        [ImportingConstructor]
        public FilterService(IAuditedOperationRepository auditedOperationRepository,IUserRepository usersRepository)
        {
            this._auditedOperationRepository = auditedOperationRepository;
            this._usersRepository = usersRepository;
        }

        #endregion

        #region IFilterService

        IEnumerable<User> IFilterService.GetUsers()
        {
            return _usersRepository.GetAll();
        }

        IEnumerable<string> IFilterService.GetFileTypes()
        {
            var fileTypes = _auditedOperationRepository.Find(u => !string.IsNullOrEmpty(u.FileType)).OrderBy(u => u.FileType).Select(u => u.FileType).Distinct();
            return fileTypes;
        }

        IEnumerable<string> IFilterService.GetHosts()
        {
            var hosts = _auditedOperationRepository.Find(u => !string.IsNullOrEmpty(u.ServerName)).OrderBy(u => u.ServerName).Select(u => u.ServerName).Distinct();
            return hosts;
        }

        IEnumerable<string> IFilterService.GetPolicies()
        {
            return _auditedOperationRepository.Find(u => !string.IsNullOrEmpty(u.PolicyName)).OrderBy(u => u.PolicyName).Select(u => u.PolicyName).Distinct();
        }

        #endregion
    }
}